package com.ljs.controller;

import com.ljs.entity.User;
import com.ljs.respository.UserMapper;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserHaddler {
    @Resource
    UserMapper userMapper;
    @RequestMapping("/findall/{index}/{limit}")
    public List<User> sel(@PathVariable("index") int index, @PathVariable("limit") int limit){

        return userMapper.selUser(index,limit);
    }
    @RequestMapping("/count")
    public  int selCount(){
        return userMapper.count();
    }
    @RequestMapping("/name/{na}")
    public  String name(@PathVariable("na") String name){
        return  name+"有"+userMapper.selbyname(name);
    }
    @RequestMapping("/upd/{id}")
    public  User selbyid(@PathVariable("id") int id){
        return userMapper.selbyid(id);
    }
    @RequestMapping("/update")
    public  boolean update(@RequestBody User menu){

        return  userMapper.update(menu);
    }

    @RequestMapping("/delete/{id}")
    public  boolean delete(@PathVariable("id") int id){
        return userMapper.delete( id);
    }
    @RequestMapping("/save")
    public  boolean save(@RequestBody  User user){
        return userMapper.add(user);

    }

}
